<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Login_c extends CI_Controller {
        function __construct() {
            parent::__construct();
            $this->load->model(array('coordinator_m'));
        }
        function index($msg = '') {
            $data['content'] = 'pages/login';
            $data['title'] = 'Login Page';
            $data['current_page'] = 'login-page';
            $data['class'] = '';
            $data['msg'] = $msg;
            if($this->session->userdata('is_logged_in')) {
                redirect(site_url().'dashboard');
            }else{
                $this->load->view('includes/template', $data);
            }
        }
        
        function validate_user() {
            $data = array(
                'email' => $this->input->post('email'),
                'pass' => $this->input->post('password'),
            );
            $result = $this->coordinator_m->validate_credentials($data);
            if ($result != FALSE) {
                $session_data = array(
                    'accid' => $result->coordinator_id,
                    'lname' => $result->lname,
                    'fname' => $result->fname,
                    'mname' => $result->mname,
                    'is_logged_in' => true
                );

                $this->session->set_userdata($session_data);
                redirect('dashboard');
            } else {
                $this->index('<p class="error-msg">Email address and password do not match.</p>');
            }
        }
        
        function logout() {
            $this->session->sess_destroy();
            $this->index('<p class="success-msg">Logout successful.</p>');
        }
    }
    
/* End of file login_c.php */
/* Location: ./application/controllers/login_c.php */
